package config

import "github.com/spf13/viper"

type Config struct {
	Name string
}

func (c *Config)Init() error {
	if c.Name != "" {
		viper.SetConfigFile(c.Name)
	} else {
		viper.AddConfigPath("./conf")
		viper.SetConfigName("config")
	}

	viper.SetConfigType("yaml")
	viper.AutomaticEnv()

	if err := viper.ReadInConfig(); err != nil {
		return err
	}

	return nil
}

func InitConfig(cfg string) error  {
	c := Config{
		Name: cfg,
	}

	if err := c.Init(); err != nil {
		return err
	}

	return nil
}